﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;

namespace HML
{
    /// <summary>
    /// 缩放窗体基类
    /// </summary>
    [Description("缩放窗体基类")]
    [ToolboxItem(true)]
    public abstract class DpiForm : Form, IDpiControl
    {
        #region 新增属性

        private float scaleDpi = 1.0f;
        /// <summary>
        /// 控件当前缩放Dpi
        /// </summary>
        [Description("控件当前缩放Dpi")]
        [Browsable(false)]
        [Localizable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual float ScaleDpi
        {
            get { return this.scaleDpi; }
            set
            {
                if (value <= 0)
                    return;

                this.scaleDpi = value;
                this.OnScaleDpiChangedInitialize();
            }
        }

        #endregion

        public DpiForm()
        {

        }

        #region 重写

        protected override void CreateHandle()
        {
            base.CreateHandle();

            this.ScaleDpi = DpiHelper.GetControlDpi(this);
        }

        #endregion

        #region 要实现

        /// <summary>
        /// 控件DPI更改后重新初始化控件Rectangle信息
        /// </summary>
        protected abstract void OnScaleDpiChangedInitialize();

        #endregion
    }

}
